package com.fanfan.SmartPensionSystembackend.controller;

import com.fanfan.SmartPensionSystembackend.entity.DailyDataBaseInfo;
import com.fanfan.SmartPensionSystembackend.entity.DailyDataDailyData;
import com.fanfan.SmartPensionSystembackend.entity.DailyDataTijianData;
import com.fanfan.SmartPensionSystembackend.service.DailyDataService;
import com.fanfan.SmartPensionSystembackend.utils.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description DailyDataController
 * @Author Guangdi Chen
 * @Date 2025-03-19
 */
@CrossOrigin
@RestController
@RequestMapping("/dailyData")
public class DailyDataController {
    @Autowired
    private DailyDataService dailyDataService;
    // 获取所有用户信息
    @RequestMapping("/getAllDailyData")
    public Map<String, Object> getAllDailyData() {
        try {
            List<DailyDataBaseInfo> dailyDataBaseInfos = dailyDataService.getAllDailyData();
            System.out.println(dailyDataBaseInfos);
            // 获取所有用户信息
            return ResponseUtil.success("获取所有用户信息成功", dailyDataBaseInfos);
        } catch (Exception e) {
            return ResponseUtil.error("获取所有用户信息失败：" + e.getMessage());        }
    }

    // 根据userId获取信息
    @RequestMapping("/screenDailyDataWithId")
    public Map<String, Object> screenDailyDataWithId(@RequestParam String userId) {
        try {
            DailyDataBaseInfo dailyDataBaseInfo = dailyDataService.screenDailyDataWithId(userId);
            System.out.println(dailyDataBaseInfo);
            // 获取所有用户信息
            return ResponseUtil.success("获取所有用户信息成功", dailyDataBaseInfo);
        } catch (Exception e) {
            return ResponseUtil.error("获取所有用户信息失败：" + e.getMessage());        }
    }

    // 根据住址获取信息
    @RequestMapping("/screenDailyDataWithAddress")
    public Map<String, Object> screenDailyDataWithAddress( @RequestParam String buildingNo, @RequestParam String floorNo, @RequestParam String roomNo) {
        try {
            System.out.println(buildingNo);
            System.out.println(floorNo);
            System.out.println(roomNo);
            List<DailyDataBaseInfo> dailyDataBaseInfos = dailyDataService.screenDailyDataWithAddress(buildingNo,floorNo,roomNo);
            System.out.println(dailyDataBaseInfos);
            // 获取所有用户信息
            return ResponseUtil.success("获取所有用户信息成功", dailyDataBaseInfos);
        } catch (Exception e) {
            return ResponseUtil.error("获取所有用户信息失败：" + e.getMessage());        }
    }

    // 提交日常数据
    @RequestMapping("/submitDailyData")
    public Map<String, Object> submitDailyData(@RequestBody DailyDataDailyData dailyData) {
        try {
            System.out.println(dailyData);
            int result = dailyDataService.insertDailyData(dailyData);
            if (result > 0) {
                return ResponseUtil.success("提交日常数据成功", dailyData);
            } else {
                return ResponseUtil.error("提交日常数据失败");
            }
        } catch (Exception e) {
            return ResponseUtil.error("提交日常数据失败：" + e.getMessage());
        }
    }

    // 提交体检数据
    @RequestMapping("/submitCheckData")
    public Map<String, Object> submitTijianData(@RequestBody DailyDataTijianData dailyData) {
        try {
            System.out.println(dailyData);
            int result = dailyDataService.insertTijianData(dailyData);
            if (result > 0) {
                return ResponseUtil.success("提交体检数据成功", dailyData);
            } else {
                return ResponseUtil.error("提交体检数据失败");
            }
        } catch (Exception e) {
            return ResponseUtil.error("提交体检数据失败：" + e.getMessage());
        }
    }
}
